/*week05 实验3
从键盘上输入年和月，输出该月份有多少天
比如，输入：
Enter year and month:2020 4 ↙
输出
There 30 days in 2020-04
程序的核心算法
1,3,5,7,8,10,12 -->31
4,6,9,11-->30
2:29/28
*/
#include <stdio.h>
int main(){
    //声明变量
    int year, month, dayNum;
    printf("Enter year and month:");
    scanf("%d%d",&year,&month);
    //使用表达式对应值进行选择分支
   switch (month)
   {
   case 1:
   case 3:
   case 5:
   case 7:
   case 8:
   case 10:
   case 12:
    dayNum = 31;//相同性质的月份共享同一个语句
    break;
   case 4:
   case 6:
   case 9:
   case 11:
    dayNum = 30;
    break;
   case 2://闰年的判断
    if ((year%4==0&&year%100!=0)||year%400==0)
    {
        dayNum = 29;
    }
    else
        dayNum = 28;
    break;
   default:
   dayNum = -1;
    break;
   }
   if(dayNum == -1){
    printf("Valid input!");
   }
   else
   {
    printf("There %d days in %4d-%02d",dayNum,year,month);//P79有详细说明
   }
   
}